from sqlalchemy import Column, Integer, String, Text, Boolean, Float
from flask_appbuilder import Model


class BackEnd(Model):
    id = Column(Integer, primary_key=True)
    host = Column(String(50), unique=True, nullable=False)
    port = Column(Integer, nullable=False)
    active = Column(Boolean, nullable=False)
    desc = Column(Text(250))

    def __repr__(self):
        return self.host + ':' + str(self.port)


class MyAppLog(Model):
    id = Column(Integer, primary_key=True)
    name = Column(String(50))
    msg = Column(String)
    args = Column(String) #array type, coding as json
    levelname = Column(String(10))
    levelno = Column(Integer)
    pathname = Column(String)
    filename = Column(String(50))
    module = Column(String(50))
    exc_text = Column(String)
    stack_info = Column(String)
    lineno = Column(Integer)
    funcName = Column(String(50))
    created = Column(Float)
    msecs = Column(Float)
    thread = Column(Integer)
    threadName = Column(String(50))
    processName = Column(String(50))
    processId = Column(Integer)
    backend = Column(String)

    def __repr__(self):
        return str(self.id)

    def is_valid(self):
        if self.name is None:
            return False
        if self.levelname is None:
            return False
        if self.levelno is None:
            return False
        if self.pathname is None:
            return False
        if self.filename is None:
            return False
        if self.module is None:
            return False
        if self.lineno is None:
            return False
        if self.funcName is None:
            return False
        if self.created is None:
            return False
        return True


